package com.karina.visualization.chart.model;

import com.google.gwt.event.shared.GwtEvent;
import com.google.gwt.event.shared.GwtEvent.Type;
import com.google.gwt.event.shared.HandlerManager;

@SuppressWarnings("deprecation")
public class DataModel<T> implements HasModelHandler {

	private final HandlerManager hanlderManager = new HandlerManager(this);

	private T obj;

	@Override
	public void fireEvent(GwtEvent<?> event) {
		this.hanlderManager.fireEvent(event);
	}

	@Override
	public void addModelHandler(Type<ModelEventHandler> type,
			ModelEventHandler handler) {
		this.hanlderManager.addHandler(type, handler);
	}

	public void setValue(T obj) {
		if (obj != this.obj) {
			this.obj = obj;
			fireEvent(new ModelEvent(this));
		}

	}

	protected DataModel<T> copy(DataModel<T> target) {
		target.left = left;
		target.right = right;
		target.top = top;
		target.bottom = bottom;
		return target;
	}

	public T getValue() {
		return obj;
	}

	public void setLeft(int left) {
		this.left = left;
	}

	public int getLeft() {
		return left;
	}

	public void setRight(int right) {
		this.right = right;
	}

	public int getRight() {
		return right;
	}

	public void setTop(int top) {
		this.top = top;
	}

	public int getTop() {
		return top;
	}

	public void setBottom(int bottom) {
		this.bottom = bottom;
	}

	public int getBottom() {
		return bottom;
	}

	private int left = 0;
	private int right = 0;
	private int top = 0;
	private int bottom = 0;

	public SeriesModel cloneMe() {
		return null;
	}

	@SuppressWarnings("unchecked")
	protected DataModel<T> createStepModel(DataModel<T> t, double rate) {
		return (DataModel<T>) cloneMe();
	}
}
